package com.web.controller;

import com.core.dto.UserDTO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 * User: xf
 * Date: 2016/4/14
 * Time: 22:41
 * To change this template use Editor | File and Code Templates.
 */
@Controller
@RequestMapping("/thy")
public class ThymeleafController {

    @RequestMapping(value = "form", method = RequestMethod.GET)
    public ModelAndView home(Model model) {
        model.addAttribute("userDTO", new UserDTO());
        return new ModelAndView("home", "userDTO", new UserDTO());
    }

    @RequestMapping(value = "form", method = RequestMethod.POST)
    public String click(@Valid UserDTO userDTO, Errors errors) {
        if (errors.hasErrors()) {
            return "home";
        }
        System.out.println(userDTO.getGuid());
        System.out.println(userDTO.getNickname());
        System.out.println(userDTO.getUsername());
        System.out.println(userDTO.getPassword());
        System.out.println("My Thymeleaf Page Is OK !");
        return "home";
    }

}
